package com.amanda.sxy.controller;

import com.alibaba.fastjson.JSONObject;
import com.amanda.sxy.entity.Rank;
import com.amanda.sxy.service.RankService;
import com.amanda.sxy.utils.Consts;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 评价 前端控制器
 * @author stone
 */
@RestController
public class RankController {
    @Resource
    private RankService service;

    /**
     * 新增评价
     */
    @RequestMapping(value = "/rank/add", method = RequestMethod.POST)
    public Object add(Rank rank) {
        JSONObject jsonObject = new JSONObject();
        boolean flag = service.insertRank(rank);
        if(flag) {
            jsonObject.put(Consts.CODE, 1);
            jsonObject.put(Consts.MSG, "评价成功");
            return jsonObject;
        }
        jsonObject.put(Consts.CODE, 0);
        jsonObject.put(Consts.MSG, "评价失败");
        return jsonObject;
    }

    /**
     * 计算平均分,根据SongListId查询rank
     */
    @RequestMapping(value = "/rank", method = RequestMethod.GET)
    public Object rankOfSongListId(Integer songListId) {
        return service.rankOfSongListId(songListId);
    }
}

